//app.js
App({
  onLaunch: function () {
    // 展示本地存储能力
    console.log('公共函数')
    const that = this
    // 获取用户信息
    wx.getSetting({
      success: function(res) {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
          wx.getUserInfo({
            lang: 'zh_CN',
            success: res => {
              // 可以将 res 发送给后台解码出 unionId
              that.globalData.userInfo = res.userInfo
              // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
              // 所以此处加入 callback 以防止这种情况
              if (that.userInfoReadyCallback) {
                that.userInfoReadyCallback(res)
              }
            }
          })
        }
      }
    })
    // 获取系统状态栏信息
    wx.getSystemInfo({
      success: function(e) {
        that.globalData.StatusBar = e.statusBarHeight;
        let custom = wx.getMenuButtonBoundingClientRect();
        that.globalData.Custom = custom;
        const CustomBar = custom.bottom + custom.top - e.statusBarHeight
        that.globalData.CustomBar = CustomBar;
        that.globalData.scrollHeight = e.windowHeight - CustomBar - e.statusBarHeight;
        that.globalData.winW = e.windowWidth
        that.globalData.winH = e.windowHeight
      }
    })
    // 读取存储数据
    var userCode = wx.getStorageSync('userCode')
    if (userCode) {
      // console.log("有usercode")
      wx.switchTab({
        url: '/pages/index/index',
      })
    }
    const userInfo = wx.getStorageSync('userInfo')
    if (userInfo === '') {
      // wx.navigateTo({
      //   url: '/pages/login/index',
      // })
      wx.reLaunch({
        url: '/pages/login/index'
      })
    }
    
  },
  globalData: {
    // userInfo: null,
    // baseUrl: 'https://www.zgajf.com/JFPORT/', **https://www.zgajf.com/static/images/
    // serverUrl: 'https://www.zgajf.com/JFPORT/uploadFiles/uploadImgs/',
    // imgSever: 'https://www.zgajf.com/static/images/'
    // baseUrl: 'https://192.168.1.31:443/JFPORT_war_exploded/',
    // baseUrl: 'https://192.168.1.31:443/JFPORT_war_exploded/',
    // serverUrl: 'https://192.168.1.31:443/JFPORT_war_exploded/uploadFiles/uploadImgs/',
    // imgSever: 'https://192.168.1.31:443/JFPORT_war_exploded/static/images/',
    // iconImgUrl:'https://192.168.1.31:443/JFPORT_war_exploded/static/images/'

    // 这是全局的数据， 上面图片地址失效了
    baseUrl: 'https://gz-wnkj.com/JFPORT_war/', //基准地址
    serverUrl: 'https://gz-wnkj.com/JFPORT_war/uploadFiles/uploadImgs/',
    imgSever: 'https://gz-wnkj.com/JFPORT_war/static/images/',
    iconImgUrl:'https://gz-wnkj.com/JFPORT_war/static/images/'
  }
})